fix: Surface all config loading errors in preAction hook#124
Merged
Conversation
The preAction hook previously only reported config errors when --config-file or --use-context were explicitly passed, silently discarding failures in the common case. Commands would proceed without config and produce confusing downstream errors with exit 0. Now all config loading failures write to stderr and exit 1. The version command is exempt since it does not require configuration.
JoshMock
approved these changes
Apr 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
preActionhook previously only reported config errors when--config-fileor--use-contextwere explicitly passed (else if), silently discarding failures in the common casemissing_configfrom the transport layer) with exit code 0, or silently connect to localhost:9200else if (configPath != null || contextName != null)toelseso all config loading failures write to stderr and exit 1versioncommand which does not require configurationCloses #97
Closes #102
Test plan
elastic es infoin a config-free directory exits 1 with "No configuration file found" on stderrelastic es info --config-file /nonexistentexits 1 with error on stderrelastic version --jsonstill succeeds without configelastic es infoin empty dir shows clean error (no silent fallback to localhost:9200)